package com.bocai.dahuatech.ui.activity;

import android.content.Intent;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.dahuatech.Bean.IndividualBean;
import com.bocai.dahuatech.Bean.PersonInfoBean;
import com.bocai.dahuatech.R;
import com.bocai.dahuatech.base.BaseActivity;
import com.bocai.dahuatech.event.MainEvent;
import com.bocai.dahuatech.utils.SharePrefencesUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 个人资料
 */
public class ProfilesActivity extends BaseActivity {

    @Bind(R.id.tv_profile_distributor)
    TextView tvDistributor;
    @Bind(R.id.tv_profile_username)
    TextView tvUserName;
    @Bind(R.id.tv_profile_companyname)
    TextView tvCompaanyName;
    @Bind(R.id.tv_profile_changephone)
    TextView tvChangePhone;
    @Bind(R.id.tv_profile_phone)
    TextView tvPhone;
    @Bind(R.id.tv_profile_message)
    TextView tvMessage;
    @Bind(R.id.tv_profile_setfenxiaoshang)
    TextView tvSetFenxiaoshang;
    PersonInfoBean bean;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.tv_profile_usertype)
    TextView tvProfileUsertype;
    @Bind(R.id.tv_profile_money)
    TextView tvProfileMoney;
    @Bind(R.id.tv_profile_address)
    TextView tvProfileAddress;
    @Bind(R.id.ll_profile_fxs)
    LinearLayout llProfileFxs;
    @Bind(R.id.tv_profile_changecompanyname)
    TextView tvUpdataCompanyName;

    @Override
    protected int contentView() {
        return R.layout.activity_profiles;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        initToolbar(R.string.profiles);
        bean = (PersonInfoBean) getIntent().getSerializableExtra("data");
        setDatas();
        initEvent();
    }

    @Override
    public void onEventMainThread(MainEvent event) {
        super.onEventMainThread(event);
        if(event.msg.equals("updateCompanyName"))
        {
            tvCompaanyName.setText(SharePrefencesUtil.getCompanyName(this));
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        tvPhone.setText(SharePrefencesUtil.gettel(this));
    }

    private void setDatas() {
        try {
            {
                llProfileFxs.setVisibility(View.VISIBLE);
                tvProfileAddress.setText(bean.getProvince() + bean.getCity() + bean.getArea());
                if(!"".equals(bean.getContractAmount())){

                    tvProfileMoney.setText(bean.getContractAmount()+getResources().getString(R.string.wanyuan));
                }
            }
            if(SharePrefencesUtil.getFAccessFlag(this)==7){
                tvProfileUsertype.setText(R.string.person);
                tvUpdataCompanyName.setVisibility(View.VISIBLE);

            }else if(bean.getStatus()==2||bean.getStatus()==3||bean.getStatus()==4){
                tvProfileUsertype.setText(R.string.distributoring);

            }else if(SharePrefencesUtil.getFAccessFlag(this)==2){
                tvProfileUsertype.setText(R.string.distributor);

            }
            if(bean.getStatus()==0){
                tvProfileUsertype.setText(R.string.distributorno);
                tvMessage.setVisibility(View.VISIBLE);
                tvMessage.setText(bean.getAuditReason());

            }
            tvUserName.setText(bean.getLoginName());
            tvCompaanyName.setText(SharePrefencesUtil.getCompanyName(this));
            tvSetFenxiaoshang.setText(R.string.setting);
            tvDistributor.setText(bean.getDistributor());
        } catch (Exception e) {
            showToast(R.string.neterror);
        }

    }

    @Override
    protected void initEvent() {
        super.initEvent();
        tvChangePhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(ProfilesActivity.this, SettingPhoneActivity.class));
            }
        });
        tvSetFenxiaoshang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(ProfilesActivity.this, RegistDistributorSecendActivity.class);
                IndividualBean bean = new IndividualBean();
                intent1.putExtra("register", bean);
                intent1.putExtra("what", "certifiled");
                startActivity(intent1);
            }
        });
        tvUpdataCompanyName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(ProfilesActivity.this, UpdataCompanyNameActivity.class));
            }
        });
    }
}
